@echo off
setlocal enabledelayedexpansion

:: 设置 VS Code 路径
set "VSCODE_PATH=%localappdata%\Programs\Microsoft VS Code\Code.exe"
if not exist "!VSCODE_PATH!" (
    set "VSCODE_PATH=C:\Users\Dowstone\AppData\Local\Programs\Microsoft VS Code\Code.exe"
)

:: 检查 VS Code 是否存在
if not exist "!VSCODE_PATH!" (
    echo 错误: 未找到 VS Code 可执行文件
    echo 请检查路径是否正确: !VSCODE_PATH!
    pause
    exit /b 1
)

echo 正在添加 VS Code 右键菜单选项...
echo VS Code 路径: !VSCODE_PATH!

:: 1. 右键文件时"通过VS Code打开"
reg add "HKEY_CLASSES_ROOT\*\shell\VSCode" /v "" /t REG_SZ /d "通过VS Code打开" /f
reg add "HKEY_CLASSES_ROOT\*\shell\VSCode" /v "Icon" /t REG_SZ /d "!VSCODE_PATH!,0" /f
reg add "HKEY_CLASSES_ROOT\*\shell\VSCode\Command" /v "" /t REG_SZ /d "\"!VSCODE_PATH!\" \"%%1\"" /f

:: 2. 右键文件夹空白部分时"通过VS Code打开"
reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode" /v "" /t REG_SZ /d "通过VS Code打开" /f
reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode" /v "Icon" /t REG_SZ /d "!VSCODE_PATH!,0" /f
reg add "HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode\Command" /v "" /t REG_SZ /d "\"!VSCODE_PATH!\" \"%%V\"" /f

:: 3. 右键文件夹时"通过VS Code打开"
reg add "HKEY_CLASSES_ROOT\Directory\shell\VSCode" /v "" /t REG_SZ /d "通过VS Code打开" /f
reg add "HKEY_CLASSES_ROOT\Directory\shell\VSCode" /v "Icon" /t REG_SZ /d "!VSCODE_PATH!,0" /f
reg add "HKEY_CLASSES_ROOT\Directory\shell\VSCode\Command" /v "" /t REG_SZ /d "\"!VSCODE_PATH!\" \"%%1\"" /f

echo.
echo VS Code 右键菜单选项已成功添加!
echo.
echo 已添加以下功能:
echo 1. 右键文件时"通过VS Code打开"
echo 2. 右键文件夹空白部分时"通过VS Code打开"
echo 3. 右键文件夹时"通过VS Code打开"
echo.
pause
